<?php
namespace app\common\model\power;
use think\Model;
use think\Db;
use app\common\model\user\User;
class Rolepowerlnk extends Model
{
     // 设置当前模型对应的完整数据表名称
        protected $table = 'rolepowerlnk';
        protected $pk = 'LnkId';
    public function roleInfo(){
        return $this->hasOne('app\common\model\power\Rolepower','PowerCode','PowerCode');
    }

   	/**
   	 * 获取操作菜单
   	 * @param  string $str [description]
   	 * @return [type]      [description]
   	 */
    public static function getpowerlnk($str = 'index'){
        $powercode = Rolepower::getpowercode();
        $rdata = Rolepowerlnk::where('PowerCode','in', $powercode)->where('State',1)->where('ShowPosition',$str)->with('roleInfo')->order('Zindex desc,PowerCode asc')->select();
        $rdata = $rdata->visible(['Icon','Img','PowerCode','Title','Url','Zindex','role_info.Title','role_info.Zindex','role_info.PowerType']);
        //根据 url  去掉重复的功能
        $lsarr = [];
        $rdata = $rdata->toArray();
        foreach ($rdata as $key => $value) {
            if(in_array($value['Url'],$lsarr)){
                unset($rdata[$key]);
            }else{
                $lsarr[] = $value['Url'];
            }
        }
        $rdata = array_values($rdata);
        return $rdata;
    }
}
